﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Domotica.Gazing.Calibration
{
    internal class ScreensProcessor : Processor
    {
        public ScreensProcessor(Calibrator calibrator) 
            : base(calibrator, CalibrationState.Smoothing)
        {
        }

        protected override ProcessList Initialize()
        {
            ProcessList l = new ProcessList();

            CalibratorScreen primary = Calibrator.ScreenList.GetPrimary();
            l.Add(new ProcessSetForm(primary.GetCenter(this.Calibrator.FormGetSize())));
            l.Add(new ProcessSetFormTopText("Calibrate screens"));

            AddPerScreenProcesses(l, primary);

            foreach (CalibratorScreen screen in Calibrator.ScreenList)
            {
                if (!screen.Screen.Primary)
                {
                    AddPerScreenProcesses(l, screen);
                }
            }

            l.Add(new ProcessSetFormMiddleText("Done"));

            return l;
        }

        private void AddPerScreenProcesses(ProcessList l, CalibratorScreen screen)
        {
            l.Add(new ProcessSetFormBottomText(""));
            l.Add(new ProcessSetFormMiddleText("Follow me"));
            l.Add(new ProcessWait(500));
            l.Add(new ProcessFormMove(screen.TopLeft(this.Calibrator.FormGetSize()), 1000));
            l.Add(new ProcessSetFormBottomText("Look at me"));
            l.Add(new ProcessGazeClick(screen.SetTrackPointTopLeft));

            l.Add(new ProcessSetFormBottomText(""));
            l.Add(new ProcessSetFormMiddleText("Follow me"));
            l.Add(new ProcessWait(500));
            l.Add(new ProcessFormMove(screen.BottomRight(this.Calibrator.FormGetSize()), 2000));
            l.Add(new ProcessSetFormBottomText("Look at me"));
            l.Add(new ProcessGazeClick(screen.SetTrackPointBottomRight));
        }
    }
}
